<?php
namespace app\index\controller;
/**
 * Created by Submint Text.
 * User: hetaoren<452649510@qq.com>
 * Date: 2017/03/10
 * Explain: 销售控制器
 */
class Sales extends Base{
   /**
    * 查看列表
    */
    public function index(){
        session("createTime",null);
        session("goodsId",null);
        $shopList = model('shops')->where(['dataFlag'=>1])->column('shopId,shopName');
        $this->assign("shopList",$shopList);
        return $this->fetch();
    }
    /**
     * 获取分页
     */
    public function pageQuery(){
        $where = [];
        $where['dataFlag'] = 1;
        $shopId = input('shopId');
        if($shopId != '')$where['shopId'] = $shopId;
        $createTime = input('createTime');
        if($createTime!='')$where['createTime'] = $createTime;
        $goodsName = input('goodsName');
        if($goodsName != '')$where['goodsName'] = ['like',"%$goodsName%"];
        return model('orders')->field('createTime,goodsName,sum(saleNum) as saleSum,goodsId')->group('createTime,goodsId')->where($where)->order('orderId desc')->paginate(input('pagesize/d'))->toArray();
    }
   /**
    * 查看列表
    */
    public function info(){
        $createTime = input('createTime');
        $goodsId = input('goodsId');
        session("createTime",$createTime);
        session("goodsId",$goodsId);
        $shopList = model('shops')->where(['dataFlag'=>1])->column('shopId,shopName');
        $this->assign("shopList",$shopList);
        return $this->fetch();
    }
    /**
     * 获取分页
     */
    public function pageQuery2(){
        $where = [];
        $where['dataFlag'] = 1;
        $where['createTime'] = session("createTime");
        $where['goodsId'] = session("goodsId");
        $shopId = input('shopId');
        if($shopId != '')$where['shopId'] = $shopId;
        $goodsName = input('goodsName');
        if($goodsName != '')$where['goodsName'] = ['like',"%$goodsName%"];
        $page = model('orders')->where($where)->order('orderId desc')->paginate(input('pagesize/d'))->toArray();
        if(count($page['Rows'])>0){
            $shopList = model('shops')->where(['dataFlag'=>1])->column('shopId,shopName');
            foreach ($page['Rows'] as $key => $v){
                $page['Rows'][$key]['shopName'] = isset($shopList[$v['shopId']]) ? $shopList[$v['shopId']] : '';
            }
        }
        return $page;
    }
}
